//
//  YTHomeMarqueeCell.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/11.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTHomeMarqueeCell.h"
#import "UUMarqueeView.h"


@interface YTHomeMarqueeCell ()<UUMarqueeViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *marqueeView;
@property(nonatomic ,strong)UUMarqueeView *marquee;
@end
@implementation YTHomeMarqueeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    CGRect frame = iPhone5 ? CGRectMake(0, 0, self.marqueeView.bounds.size.width - 20, self.marqueeView.bounds.size.height) : self.marqueeView.bounds;
    self.marquee = [[UUMarqueeView alloc] initWithFrame:frame direction:UUMarqueeViewDirectionUpward];
    self.marquee.delegate = self;
    self.marquee.timeIntervalPerScroll = 3.0f;    // 条目滑动间隔
    self.marquee.scrollSpeed = 30.0f;    // 滑动速度
    self.marquee.itemSpacing = 20.0f;    // 左右相邻两个条目的间距，当左侧条目内容的长度超出marquee view整体长度时有效
    self.marquee.touchEnabled = YES;    // 设置为YES可监听点击事件，默认值为NO
    [self.marqueeView addSubview:self.marquee];
    
    
}

- (void)setFlashList:(NSArray<YTNewFlashModel *> *)flashList
{
    _flashList = flashList;
    
    [self.marquee reloadData];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    

    
}

//- (void)cellDidEndDisplay
//{
//    [self.marquee pause];
//}

#pragma mark: - UUMarqueeViewDelegate
- (NSUInteger)numberOfVisibleItemsForMarqueeView:(UUMarqueeView*)marqueeView {
    // 指定可视条目的行数，仅[UUMarqueeViewDirectionUpward]时被调用。
    // 当[UUMarqueeViewDirectionLeftward]时行数固定为1。
    return 1;
}

- (NSUInteger)numberOfDataForMarqueeView:(UUMarqueeView*)marqueeView
{
    return self.flashList.count;
}
- (void)createItemView:(UIView *)itemView forMarqueeView:(UUMarqueeView*)marqueeView
{
    UILabel *content = [[UILabel alloc] initWithFrame:itemView.bounds];
    content.font = [UIFont systemFontOfSize:14];
    content.tag = 99999;
    content.numberOfLines = 2;
    [itemView addSubview:content];
}
- (void)updateItemView:(UIView *)itemView atIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView
{
    UILabel *content = [itemView viewWithTag:99999];
    content.text = self.flashList[index].post_title;
    
}

- (void)didTouchItemViewAtIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView
{

    NSAssert(self.marqueeClickBlock != nil, @"marqueeClickBlock 不能为nil");
    self.marqueeClickBlock(self.flashList[index]);

   
}
@end
